import {createSlice,createAsyncThunk} from '@reduxjs/toolkit';
import {getMovieList} from '../../api/api';

export const getMovieAct  = createAsyncThunk('movie/getMovie', async () => {
    const re = await getMovieList();
    // console.log(re);

    return re.data.data.list
})


const movieSlice = createSlice({
    name : 'movie',
    initialState : {
       movieList : []
    },
    reducers : {

    },
    extraReducers : {
        [getMovieAct.fulfilled](preState,action) {
            
            preState.movieList = action.payload
            console.log("异步数据加载完成");
        },
        [getMovieAct.rejected]() {
            console.log('异步action失败');
        },
        [getMovieAct.pending]() {
            console.log('异步action正在进行中');
        },
    }
})

export default movieSlice.reducer
